import { useDispatch } from "react-redux"
import { Content } from "./components/Content/Content"
import { Footer } from "./components/Footer/Footer"
import { Header } from "./components/Header/Header"
import { login } from "./store/userStore"
import { message } from "antd"
import { useEffect } from "react"
import { reqWhoAmI } from "./api/userApi"
import { reqGetAllTypes } from "./api/uploadApi"
import { setTypeList } from "./store/typeStore"

export default function App() {
    const dispatch = useDispatch()
    const getAllType = async () => {
        const { data } = await reqGetAllTypes()
        dispatch(setTypeList(data))
    }

    const whoAMI = async () => {
        const { code, data } = await reqWhoAmI()
        if (code === 0) {
            dispatch(login(data))
            messageApi.success(`欢迎回来,${data.nickname}`)
        } else {

        }
    }
    useEffect(() => {
        whoAMI()
        getAllType()
    }, [])
    const [messageApi, contextHold] = message.useMessage()
    return (
        <>
            {/* header */}
            <Header></Header>
            {/* content */}
            <Content></Content>
            {/* header */}
            <Footer></Footer>
            {contextHold}
        </>
    )
}